﻿/*-------------------------------------------------------------------------
 * 版权所有：	黑客马拉松
 * 作者：		罗毅
 * 联系方式：	whluoyi@gmail.com
 * 创建时间：	2016/10/29 11:23:16
 * 版本号：		v1.0
 * 用途描述：	SuperMarieApi业务对象
 *  -------------------------------------------------------------------------*/

namespace SuperMarieApi.App.Controllers.Biz
{
    using System;
    using System.Collections.Generic;
    using System.Data;

    using SuperMarieApi.App.Controllers.Entity;
    using SuperMarieApi.App.Controllers.Framework.DataAccess;
    using SuperMarieApi.App.Controllers.Tool.Extensions;

    public class MyMusicLabBiz
    {
        /// <summary>
        /// 获取MyMusicLab列表
        /// </summary>
        /// <returns></returns>
        public static List<MyMusicLabEntity> GetMyMusicLabList()
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("SuperMarieApi.Get-MyMusicLabList");
            List<MyMusicLabEntity> lists = cmd.ExecuteEntityList<MyMusicLabEntity>();
            return lists;
        }

        /// <summary>
        /// 获取MyMusicLab列表
        /// </summary>
        /// <returns></returns>
        public static DataTable GetMyMusicLabData()
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("SuperMarieApi.Get-MyMusicLabList");
            return cmd.ExecuteDataSet().Tables[0];
        }

        /// <summary>
        /// 获取MyMusicLab详情
        /// </summary>
        /// <returns></returns>
        public static MyMusicLabEntity GetMyMusicLabObj(int MyMusicLab_ID)
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("SuperMarieApi.Get-MyMusicLab");
            cmd.SetParameterValue("@MyMusicLab_ID", MyMusicLab_ID);
            MyMusicLabEntity obj = cmd.ExecuteEntity<MyMusicLabEntity>();
            return obj;
        }

        /// <summary>
        /// 更新MyMusicLab详情
        /// </summary>
        /// <returns></returns>
        public static int SetMyMusicLabObj(MyMusicLabEntity obj)
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("SuperMarieApi.Set-MyMusicLab");
            cmd.SetParameterValue("@MyMusicLab_ID", obj.MyMusicLab_ID);
            cmd.SetParameterValue("@face_id", obj.face_id);
            cmd.SetParameterValue("@singer", obj.singer);
            cmd.SetParameterValue("@MusicUrl", obj.MusicUrl);
            cmd.SetParameterValue("@zannum", obj.zannum);
            cmd.SetParameterValue("@AddTime", obj.AddTime);
            int i = cmd.ExecuteNonQuery();
            return i;
        }

        /// <summary>
        /// 插入MyMusicLab详情
        /// </summary>
        /// <returns></returns>
        public static int InsertMyMusicLabObj(MyMusicLabEntity obj)
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("SuperMarieApi.Insert-MyMusicLab");
            cmd.SetParameterValue("@face_id", obj.face_id);
            cmd.SetParameterValue("@singer", obj.singer);
            cmd.SetParameterValue("@MusicUrl", obj.MusicUrl);
            cmd.SetParameterValue("@zannum", obj.zannum);
            cmd.SetParameterValue("@AddTime", obj.AddTime);
            object identity = cmd.ExecuteScalar();
            if (identity == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(identity);
            }
        }

        /// <summary>
        /// 分页MyMusicLab数据列表
        /// </summary>
        /// <returns></returns>
        public static DataSet PageMyMusicLabList(int pageSize, int pageIndex, string strWhere, string sortField = "MyMusicLab_ID", string sortOrder = "DESC")
        {
            if (!strWhere.SqlFilter_List())
            {
                return null;
            }
            string pagesort = "";
            string pagewhere = "";
            string pageindexsize = "";
            if (!string.IsNullOrEmpty(sortField.Trim()))
            {
                pagesort = "ORDER BY " + sortField + " " + sortOrder;
            }
            else
            {
                pagesort = "ORDER BY T.MyMusicLab_ID " + sortOrder;
            }
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                pagewhere = " WHERE " + strWhere;
            }
            pageindexsize = " WHERE TT.Row between " + ((pageIndex - 1) * pageSize + 1) + " and " + (pageIndex * pageSize);
            DataCommand cmd = DataCommandManager.GetDataCommand("SuperMarieApi.Page-MyMusicLab");
            cmd.SetParameterValue("@pagesort", pagesort);
            cmd.SetParameterValue("@pagewhere", pagewhere);
            cmd.SetParameterValue("@pageindexsize", pageindexsize);
            return cmd.ExecuteDataSet();
        }
    }
}